package com.fin.quant.domain.service.impl;

import com.fin.quant.domain.service.RankingDaoService;
import com.fin.quant.instra.mysql.mapper.RankingAssetMapper;
import com.fin.quant.instra.mysql.mapper.RankingTypeMapper;
import com.fin.quant.instra.mysql.model.RankingAsset;
import com.fin.quant.instra.mysql.model.RankingAssetExample;
import com.fin.quant.instra.mysql.model.RankingType;
import com.fin.quant.instra.mysql.model.RankingTypeExample;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 排行榜领域服务实现
 */
@Service
public class RankingDaoServiceImpl implements RankingDaoService {

    @Autowired
    private RankingTypeMapper rankingTypeMapper;

    @Autowired
    private RankingAssetMapper rankingAssetMapper;

    @Override
    public List<RankingType> getEnabledRankingTypes() {
        return rankingTypeMapper.selectByExample(null);
    }

    @Override
    public RankingType getRankingTypeById(String typeId) {
        RankingTypeExample example = new RankingTypeExample();
        example.createCriteria().andTypeIdEqualTo(typeId);
        List<RankingType> rankingTypes = rankingTypeMapper.selectByExample(example);
        return CollectionUtils.isNotEmpty(rankingTypes)?rankingTypes.get(0):null;
    }

    @Override
    public List<RankingAsset> getRankingAssets(String typeId, int limit) {
        RankingAssetExample example = new RankingAssetExample();
        example.createCriteria().andRankingTypeIdEqualTo(typeId);
        List<RankingAsset> rankingAssets = rankingAssetMapper.selectByExample(example);
        return rankingAssets;
    }
}
